package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.app.entity.TPolicyEntity;
import io.renren.modules.app.service.TPolicyService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-04-24 18:21:58
 */
@RestController
@RequestMapping("app/tpolicy")
public class TPolicyController {
    @Autowired
    private TPolicyService tPolicyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("app:tpolicy:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tPolicyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("app:tpolicy:info")
    public R info(@PathVariable("id") Integer id){
        TPolicyEntity tPolicy = tPolicyService.getById(id);

        return R.ok().put("tPolicy", tPolicy);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("app:tpolicy:save")
    public R save(@RequestBody TPolicyEntity tPolicy){
        tPolicy.setCreateTime(new Date());
        tPolicyService.save(tPolicy);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("app:tpolicy:update")
    public R update(@RequestBody TPolicyEntity tPolicy){
        tPolicy.setUpdateTime(new Date());
        ValidatorUtils.validateEntity(tPolicy);
        tPolicyService.updateById(tPolicy);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("app:tpolicy:delete")
    public R delete(@RequestBody Integer[] ids){
        tPolicyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
